package com.globallogic.vacationplanner.model.dao.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.globallogic.vacationplanner.model.dao.declaration.IProjectDao;
import com.globallogic.vacationplanner.model.entity.Project;
import com.globallogic.vacationplanner.model.entity.User;

@Repository("projectDao")
@Transactional
public class ProjectDao extends BaseDao<Project> implements IProjectDao {
	private static final long serialVersionUID = 1L;
	private static Logger LOGGER = Logger.getLogger(ProjectDao.class);

	public ProjectDao() {
		super();
		LOGGER.info("ProjectDao created");
	}

	@Override
	String getReadAllQuery() {
		return "from Project";
	}

	/**
	 * {@inheritDoc}
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<User> getUserListWithoutCreator(int id) {
		LOGGER.info("Get user list with");
		return getHibernateTemplate().findByNamedParam(
				"from User where idUser <> :id", "id", id);
	}

	/**
	 * {@inheritDoc}
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Project getProjectById(int id) {
		List<Project> projectList = getHibernateTemplate().findByNamedParam(
				"from Project where idProject  = :id", "id", id);
		return (projectList.isEmpty()) ? null : projectList.get(0);
	}

}
